package com.mumuso.mumusoitem.controller;

import com.mumuso.mumusoitem.pojo.dGoodsCollectionItemRole;
import com.mumuso.mumusoitem.service.dGoodsCollectionRoleService;
import com.mumuso.mumusoitem.utils.AjaxResult;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

import java.util.List;

import static com.mumuso.mumusoitem.utils.ParseUrl.getUrl;

@RestController
@RequestMapping("/role")
public class dGoodsCollectionRoleController {

    @Autowired
    private dGoodsCollectionRoleService dGoodsCollectionRoleService;

    /**
     * 通过制单编号获取角色信息
     *
     * @param request
     * @return
     */
    @RequestMapping("/selectRoleInfoByStaId/")
    public AjaxResult selectRoleInfoByStaId(HttpServletRequest request) {
        String queryString = request.getQueryString();
        String staffID = getUrl(queryString, "StaffID");

        if (StringUtils.isBlank(staffID)) {
            return AjaxResult.error("未被定义的参数!!!!");
        }

        try {
            List<dGoodsCollectionItemRole> collectionRole = dGoodsCollectionRoleService.selectPerInfoByStaffId(staffID);
            if (ObjectUtils.isNotEmpty(collectionRole)) {
                return AjaxResult.success(collectionRole);
            } else {
                return AjaxResult.error("为查询到该角色信息，请确定已经被分配角色!!!");
            }
        } catch (Exception e) {
            return AjaxResult.error(e.getMessage());
        }

    }

}
